package com.fyl.oauth2.dao;

import com.fyl.oauth2.domain.AuthorizationCodeEntity;
import org.apache.ibatis.annotations.*;

public interface AuthorizationCodeMapper {
    @Insert("INSERT INTO authorization_code (code, issued_at, expires_at, redirect_uri, client_id, state, code_challenge, code_challenge_method, authorization_grant_type, authenticated_principal_name, authorized_scopes, attributes) " +
            "VALUES (#{code}, #{issuedAt}, #{expiresAt}, #{redirectUri}, #{clientId}, #{state}, #{codeChallenge}, #{codeChallengeMethod}, #{authorizationGrantType}, #{authenticatedPrincipalName}, #{authorizedScopes}, #{attributes})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(AuthorizationCodeEntity authorizationCodeEntity);

    @Select("SELECT * FROM authorization_code WHERE code = #{code}")
    AuthorizationCodeEntity findByCode(@Param("code") String code);

    @Delete("DELETE FROM authorization_code WHERE code = #{code}")
    void deleteByCode(@Param("code") String code);
}
